home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / xlib / xlib06p2 / xplanput.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-17  |  7.2 KB  |  261 lines

  1. #include "xinternl.h"
  2. #include <conio.h>
  3. #include <mem.h>
  4.  
  5. extern BYTE * pbVGABuffer;
  6. extern int ScrnLogicalByteWidth;
  7. extern int LeftClip;
  8. extern int RightClip;
  9. extern xScreenCoord_t TopClip;
  10. extern xScreenCoord_t BottomClip;
  11.  
  12. static int iCurrentPlane = -1;
  13.  
  14. void x_set_write_plane(
  15.   unsigned char bPlane  //@parm Plane to write to
  16. )
  17. {
  18.   bPlane &= 0x03; //mask out so we only have 0-3 to choose from
  19.   iCurrentPlane = bPlane;
  20.   int iTemp = 0x0100;
  21.   iTemp <<= bPlane;    //set only the correct bit to 1
  22.   iTemp += MAP_MASK;  //set the map mask
  23.   //Select the write plane
  24.   outpw( SC_INDEX, iTemp );
  25. }
  26.  
  27.  
  28. void x_put_plane_masked_pbm(  /* Copy a planar bitmap from SRAM masking */
  29.   xScreenCoord_t X,    /* only non zero pixels to VRAM           */
  30.   xScreenCoord_t Y,
  31.   xPageHandle_t ScrnOffs,
  32.   BYTE * Bitmap
  33. )
  34. {
  35.   BYTE * pbSource = Bitmap;
  36.   int iWidth = *pbSource++;
  37.   int iHeight = *pbSource++;
  38.   BYTE * pbDest = pbVGABuffer + ScrnOffs + ( ScrnLogicalByteWidth * Y ) + X / 4;
  39.   BYTE * pbDestCounter = pbDest;
  40.   int iSkip = ScrnLogicalByteWidth - iWidth;
  41.   //now find out what plane of our bitmap we want to output and what
  42.   //our adjust is into the destination buffer.
  43.   int iDestPlane = X & 3;
  44.   int iAdjust = 0;
  45.   int iDifference = iCurrentPlane - iDestPlane;
  46.   if ( iDifference < 0 ) {
  47.     iAdjust = 1;
  48.     iDifference += 4;
  49.   }
  50.  
  51.   pbDestCounter = pbDest + iAdjust;
  52.   pbSource = Bitmap + 2 + iDifference * iWidth * iHeight;
  53.   for ( int iRowCounter = iHeight; iRowCounter != 0; --iRowCounter ) {
  54.     for ( int iWidthCounter = iWidth; iWidthCounter != 0; --iWidthCounter ) {
  55.       BYTE bTemp = *pbSource++;
  56.       if ( bTemp ) {
  57.         *pbDestCounter++ = bTemp;
  58.       }
  59.       else {
  60.         pbDestCounter++;
  61.       }
  62.     }
  63.     pbDestCounter += iSkip;
  64.   }
  65. }
  66.  
  67.  
  68. void x_put_plane_pbm(         /* Copy a planar bitmap from SRAM to VRAM */
  69.   xScreenCoord_t X,
  70.   xScreenCoord_t Y,
  71.   xPageHandle_t ScrnOffs,
  72.   BYTE * Bitmap
  73. )
  74. {
  75.   BYTE * pbSource = Bitmap;
  76.   int iWidth = *pbSource++;
  77.   int iHeight = *pbSource++;
  78.   BYTE * pbDest = pbVGABuffer + ScrnOffs + ( ScrnLogicalByteWidth * Y ) + X / 4;
  79.   BYTE * pbDestCounter = pbDest;
  80.  
  81.   outp( SC_INDEX, MAP_MASK );
  82.   int iPlane = X & 3;
  83.   int iAdjust = 0;
  84.   for( int iPlaneCounter = 4; iPlaneCounter != 0; --iPlaneCounter ) {
  85.     pbDestCounter = pbDest + iAdjust;
  86.     pbSource = Bitmap + 2 + ( 4 - iPlaneCounter ) * iWidth * iHeight;
  87.     outp( SC_INDEX + 1, 1 << iPlane );
  88.     for ( int iRowCounter = iHeight; iRowCounter != 0; --iRowCounter ) {
  89.       memcpy( pbDestCounter, pbSource, iWidth );
  90.       pbSource += iWidth;
  91.       pbDestCounter += ScrnLogicalByteWidth;
  92.     }
  93.     iPlane++;
  94.     if ( iPlane == 4 ) {
  95.       iAdjust = 1;
  96.     }
  97.     iPlane &= 3;
  98.   }
  99. }
  100.  
  101.  
  102. /*
  103. _ClipX() clips the x coordinates of a bitmap
  104. */
  105. inline void _ClipX(
  106.   xScreenCoord_t X,
  107.   int iWidth,
  108.   int * piOffsetFromLeft,
  109.   int * piWidthToDraw
  110. )
  111. {
  112.   *piOffsetFromLeft = LeftClip - ( X / 4 );
  113.   if ( *piOffsetFromLeft < 0 ) {
  114.     *piOffsetFromLeft = 0;
  115.   }
  116.   int iOffsetFromRight  = ( X / 4 + iWidth ) - RightClip;
  117.   if ( iOffsetFromRight < 0 ) {
  118.     iOffsetFromRight = 0;
  119.   }
  120.   *piWidthToDraw = iWidth - ( *piOffsetFromLeft + iOffsetFromRight );
  121. }
  122.  
  123.  
  124. /*
  125. _ClipY() clips the Y coordinates of a bitmap
  126. */
  127. inline void _ClipY(
  128.   xScreenCoord_t Y,
  129.   int iHeight,
  130.   int * piOffsetFromTop,
  131.   int * piHeightToDraw
  132. )
  133. {
  134.   *piOffsetFromTop = TopClip - Y;
  135.   if ( *piOffsetFromTop < 0 ) {
  136.     *piOffsetFromTop = 0;
  137.   }
  138.   int iOffsetFromBottom  = Y + iHeight - BottomClip;
  139.   if ( iOffsetFromBottom < 0 ) {
  140.     iOffsetFromBottom = 0;
  141.   }
  142.   *piHeightToDraw = iHeight - ( *piOffsetFromTop + iOffsetFromBottom );
  143. }
  144.  
  145.  
  146. int x_put_plane_masked_pbm_clipxy( /* Copy a planar bitmap from SRAM masking */
  147.   xScreenCoord_t X,          /* only non zero pixels to VRAM           */
  148.   xScreenCoord_t Y,          /* Supports clipping in the Y direction   */
  149.   xPageHandle_t ScrnOffs,
  150.   BYTE * Bitmap
  151. )
  152. {
  153.   BYTE * pbSource = Bitmap;
  154.   int iWidth = *pbSource++;
  155.   int iHeight = *pbSource++;
  156.   //first let's get our clipping dimensions.  We'll need an "offset from
  157.   //left" value, a width to draw value, an "offset from top" value, and a
  158.   //"height to draw" value.
  159.   int iOffsetFromLeft;
  160.   int iWidthToDraw;
  161.   _ClipX( X, iWidth, &iOffsetFromLeft, &iWidthToDraw );
  162.   if ( iWidthToDraw < 0 ) {
  163.     return 1;
  164.   }
  165.   //now do Y
  166.   int iOffsetFromTop;
  167.   int iHeightToDraw;
  168.   _ClipY( Y, iHeight, &iOffsetFromTop, &iHeightToDraw );
  169.   if ( iHeightToDraw < 0 ) {
  170.     return 1;
  171.   }
  172.  
  173.   BYTE * pbDest = pbVGABuffer + ScrnOffs +
  174.     ScrnLogicalByteWidth * ( Y + iOffsetFromTop ) +
  175.     X / 4 + iOffsetFromLeft;
  176.   BYTE * pbDestCounter = pbDest;
  177.  
  178.   int iSkip = ScrnLogicalByteWidth - iWidthToDraw;
  179.   outp( SC_INDEX, MAP_MASK );
  180.   int iPlane = X & 3;
  181.   int iAdjust = 0;
  182.   for( int iPlaneCounter = 4; iPlaneCounter != 0; --iPlaneCounter ) {
  183.     pbDestCounter = pbDest + iAdjust;
  184.     pbSource = Bitmap + 2 + ( 4 - iPlaneCounter ) * iWidth * iHeight + iOffsetFromTop * iWidth + iOffsetFromLeft;
  185.     outp( SC_INDEX + 1, 1 << iPlane );
  186.     for ( int iRowCounter = iHeightToDraw; iRowCounter != 0; --iRowCounter ) {
  187.       for ( int iWidthCounter = iWidthToDraw; iWidthCounter != 0; --iWidthCounter ) {
  188.         BYTE bTemp = *pbSource++;
  189.         if ( bTemp ) {
  190.           *pbDestCounter++ = bTemp;
  191.         }
  192.         else {
  193.           pbDestCounter++;
  194.         }
  195.       }
  196.       pbSource += iWidth - iWidthToDraw;
  197.       pbDestCounter += iSkip;
  198.     }
  199.     iPlane++;
  200.     if ( iPlane == 4 ) {
  201.       iAdjust = 1;
  202.     }
  203.     iPlane &= 3;
  204.   }
  205.   return 0;
  206. }
  207.  
  208.  
  209. int x_put_plane_pbm_clipxy(   /* Copy a planar bitmap from SRAM masking */
  210.   xScreenCoord_t X,     /* Supports clipping in the X&Y directions */
  211.   xScreenCoord_t Y,
  212.   xPageHandle_t ScrnOffs,
  213.   BYTE * Bitmap
  214. )
  215. {
  216.   BYTE * pbSource = Bitmap;
  217.   int iWidth = *pbSource++;
  218.   int iHeight = *pbSource++;
  219.   //first let's get our clipping dimensions.  We'll need an "offset from
  220.   //left" value, a width to draw value, an "offset from top" value, and a
  221.   //"height to draw" value.
  222.   int iOffsetFromLeft;
  223.   int iWidthToDraw;
  224.   _ClipX( X, iWidth, &iOffsetFromLeft, &iWidthToDraw );
  225.   if ( iWidthToDraw < 0 ) {
  226.     return 1;
  227.   }
  228.   //now do Y
  229.   int iOffsetFromTop;
  230.   int iHeightToDraw;
  231.   _ClipY( Y, iHeight, &iOffsetFromTop, &iHeightToDraw );
  232.   if ( iHeightToDraw < 0 ) {
  233.     return 1;
  234.   }
  235.  
  236.   BYTE * pbDest = pbVGABuffer + ScrnOffs +
  237.     ScrnLogicalByteWidth * ( Y + iOffsetFromTop ) +
  238.     X / 4 + iOffsetFromLeft;
  239.   BYTE * pbDestCounter = pbDest;
  240.  
  241.   outp( SC_INDEX, MAP_MASK );
  242.   int iPlane = X & 3;
  243.   int iAdjust = 0;
  244.   for( int iPlaneCounter = 4; iPlaneCounter != 0; --iPlaneCounter ) {
  245.     pbDestCounter = pbDest + iAdjust;
  246.     pbSource = Bitmap + 2 + ( 4 - iPlaneCounter ) * iWidth * iHeight + iOffsetFromTop * iWidth;
  247.     outp( SC_INDEX + 1, 1 << iPlane );
  248.     for ( int iRowCounter = iHeightToDraw; iRowCounter != 0; --iRowCounter ) {
  249.       memcpy( pbDestCounter, pbSource + iOffsetFromLeft, iWidthToDraw );
  250.       pbSource += iWidth;
  251.       pbDestCounter += ScrnLogicalByteWidth;
  252.     }
  253.     iPlane++;
  254.     if ( iPlane == 4 ) {
  255.       iAdjust = 1;
  256.     }
  257.     iPlane &= 3;
  258.   }
  259.   return 0;
  260. }
  261.